#include "os_core.h"


volatile uint32_t              OS_THREAD_MEMORY       g_current_thread_index =   0;
volatile os_thread_manager_st  OS_THREAD_MEMORY             g_thread_manager = {0};
static volatile int16_t                                   g_os_critical_conter = 0;
static volatile int16_t                                  g_isr_critical_conter = 0;

void os_enter_critical(void)
{
    if (g_os_critical_conter == 0)
    {
        portDISABLE_ISR(); // Disable interrupts
    }
    g_os_critical_conter++;
}
void os_exit_critical(void)
{

    if (g_os_critical_conter > 0)
    {
        g_os_critical_conter--;
        if (g_os_critical_conter == 0)
        {
            portENABLE_ISR(); // Enable interrupts
        }
    }
}

void isr_enter_critical(void)
{
    if (g_isr_critical_conter == 0)
    {
        portDISABLE_ISR(); // Disable interrupts
    }
    g_isr_critical_conter++;
}
void isr_exit_critical(void)
{
    if (g_isr_critical_conter > 0)
    {
        g_isr_critical_conter--;
        if (g_isr_critical_conter == 0)
        {
            portENABLE_ISR(); // Enable interrupts
        }
    }
}
